<?php
/*
Template Name: Portfolio
*/

	global $woo_options;
	get_header();
?>
       
    <div id="title-container">
	  <h1 class="title col-full"><?php the_title(); ?></h1>
	</div>
	 
    <div id="content" class="page col-full">
	  
		<?php if ( $woo_options[ 'woo_breadcrumbs_show' ] == 'true' ) { ?>
			<div id="breadcrumbs">
				<?php woo_breadcrumbs(); ?>
			</div><!--/#breadcrumbs -->
		<?php } ?> 
		 			
		<?php
			if ( get_query_var('paged') ) $paged = get_query_var('paged'); elseif ( get_query_var('page') ) $paged = get_query_var('page'); else $paged = 1;
			$args = array(
							'post_type' => 'portfolio', 
							'paged' => $paged, 
							'meta_key' => 'portfolio-image'
						);
			query_posts( $args );
			 
			rewind_posts();
		?>

		<div id="main" class="fullwidth"> 
				           
		    <div id="portfolio" class="col-full">
		    	
		    	<!-- Tags -->
				<?php
					$terms = $woo_options['woo_portfolio_tags'];
					if ( $terms ) {
						$terms_string = '';
						
						foreach ( explode( ', ', $terms ) as $t ) {
							$tag = trim( $t );
							$tag = str_replace (" ", "-", $tag);	
							$tag = str_replace ("/", "-", $tag);
							$tag = strtolower ( $tag );
							$terms_string .= ' <a rel="' . $tag . '" href="#" title="' . ucwords( $t ) . '">' . ucwords( $t ) . '</a>';
						} // End FOREACH Loop
				?>
		    	<div id="port-tags">
		            <div class="fl">
		                <span class="port-cat"><?php _e('Select a category:', 'woothemes'); ?> <a href="#" rel="all" class="current"><?php _e( 'All','woothemes' ); ?></a><?php echo $terms_string; ?></span>
		            </div>
			      	<div class="fix"></div>
			    </div>
			      
				<?php } ?>
				<!-- /Tags -->
				<div class="portfolio">
		        <?php if ( have_posts() ) { $count = 0; $per_row = 4; while (have_posts()) { the_post(); $count++; ?>
		        <?php 
					// Portfolio tags class
					$porttag = ""; 
					$posttags = get_the_tags(); 
					if ($posttags) { 
						foreach($posttags as $tag) { 
							$tag = $tag->name;
							$tag = str_replace (" ", "-", $tag);	
							$tag = str_replace ("/", "-", $tag);
							$tag = strtolower ( $tag );
							$porttag .= $tag . ' '; 
						} 
					}
					
					$excerpt = woo_text_trim( get_the_excerpt(), '12');
					
					$portfolio_image = get_post_meta( $post->ID, 'portfolio-image', true );
					
					if ( $count % $per_row == 0 ) { $porttag .= 'last'; }
				?>
					<div class="group post portfolio-img <?php echo trim( $porttag ); ?>">
					<a class="portfolio-img thumb <?php echo trim( $porttag ); ?>" rel="prettyPhoto['portfolio']" href="<?php echo $portfolio_image; ?>">
									<?php woo_image('key=portfolio-image&width=214&height=119&link=img&alt=' . esc_attr( get_the_title() ) . ''); ?>
									<strong><?php the_title(); ?></strong>
					</a>
					<?php if ( $excerpt ) { ?><div class="excerpt"><?php echo $excerpt; ?></div><?php } ?>
					</div>
				<?php if ($count == 4) { ?><div class="fix"></div><?php $count = 0; } ?>
		        <?php
		        	} // End WHILE Loop
		        } else {
		        ?>
	            <div class="post">
	                <p><?php _e('Sorry, no posts matched your criteria.', 'woothemes') ?></p>
	            </div><!-- /.post -->
		        <?php } // End IF Statement ?>  
				</div>	        		        
			
		    </div><!-- /#portfolio -->
                                                            
            <?php woo_pagenav(); ?>
		</div><!-- /#main -->

    </div><!-- /#content -->
		
<?php get_footer(); ?>